<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Models\Income;
use DB;
class IncomeController extends Controller
{
    
    public function __construct()
    {
        $this->middleware('checkPermission:'.config('admin.permissions.wincome.list'), ['only' => ['index', 'ajaxIndex']]);
       // $this->middleware('checkPermission:'.config('admin.permissions.role.create'), ['only' => ['create', 'store']]);
        //$this->middleware('checkPermission:'.config('admin.permissions.role.edit'), ['only' => ['edit', 'update']]);
       // $this->middleware('checkPermission:'.config('admin.global.role.action').',true', ['only' => ['mark']]);
        //$this->middleware('checkPermission:'.config('admin.permissions.role.destory'), ['only' => ['destroy']]);
       // $this->middleware('checkPermission:'.config('admin.permissions.role.show'), ['only' => ['show']]);
    }
    public  function  ajaxIndex()
    {
        $model_income = new Income();
        $pageDate = $model_income->getWorksList();
        return json_encode($pageDate, true);
        
    }
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        return view('admin.wincome.list');
        
    }
    //返回ajaxShow
    public function ajaxShow()
    {
        $model_income = new Income();
        $pageDate = $model_income->showindex();
        return json_encode($pageDate, true);
        
    }
     /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show()
    {
        return view('admin.wincome.show');
    }
    
    //ajax返回其他收入
    public  function  ajaxAll()
    {
            $model_income = new Income();
            $pageDate = $model_income->showall();
            return json_encode($pageDate, true);
    }
    
    public function all()
    {
    
        return view('admin.wincome.all');
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('admin.wincome.create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function add(Request $request)
    {
        $data['project'] = request('project','');
        $data['bar'] = request('bar','');
        $data['service'] = request('service','');
        $data['amount'] = request('amount','');
        $baifen = '0.2';//获取提成
        $ticheng = $data['amount'] * $baifen;
        

        $data['ticheng'] = strval($ticheng);
        
        
        $data['activity'] = request('activity','');
    
        $data['other'] = request('other','');
        $data['time'] = date('Y-m-d');
        $data['created_at'] = date('Y-m-d H:i:s');
        $data['type'] = 1;
        
        $model_income = new Income();
        $info =  $model_income->insert($data);
        
        var_dump($info);exit();
        
       
        
    }

    //添加外部收入管理
    public  function insert()
    {
        return view('admin.wincome.insert');
    }
    
    //添加外部收入管理
    public  function wincomeAdd()
    {
         $data['project'] = request('project','');
        $data['bar'] = request('bar','');
        $data['service'] = request('service','');
        $data['amount'] = request('amount','');
        $baifen = '0.2';//获取提成
        $ticheng = $data['amount'] * $baifen;
        

        $data['ticheng'] = strval($ticheng);
        
        
        $data['activity'] = request('activity','');
    
        $data['other'] = request('other','');
        $data['time'] = date('Y-m-d');
        $data['created_at'] = date('Y-m-d H:i:s');
        $data['type'] = 2;
        
        $model_income = new Income();
        $info =  $model_income->insert($data);
        
        var_dump($info);exit();
    }
    
    
    
    //添加其他收入guanli
    public function other()
    {
        return view('admin.wincome.other');
    }
    
    
    public function otherAdd()
    {
        $data['project'] = request('project','');
        $data['bar'] = request('bar','');
        $data['service'] = request('service','');
        $data['amount'] = request('amount','');
        $baifen = '0.2';//获取提成
        $ticheng = $data['amount'] * $baifen;
        

        $data['ticheng'] = strval($ticheng);
        
        
        $data['activity'] = request('activity','');
    
        $data['other'] = request('other','');
        $data['time'] = date('Y-m-d');
        $data['created_at'] = date('Y-m-d H:i:s');
        $data['type'] = 2;
        
        $model_income = new Income();
        $info =  $model_income->insert($data);
        
        var_dump($info);exit();
    }
    
    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
